package chapter04;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestWaitNofity {
    final static Object obj=new Object();
    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            log.info("t1线程执行");
            synchronized (obj){// 线程等待—>阻塞
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            log.info("t1执行其他线程");
        },"t1").start();
        new Thread(()->{
            log.info("t2线程执行");
            synchronized (obj){// 线程等待—>阻塞
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            log.info("t2执行其他线程");
        },"t2").start();

        Thread.sleep(2000);
        log.info("main唤醒其他线程执行");
        synchronized (obj){
//            obj.notify();// 通知阻塞线程开启
            obj.notifyAll();// 唤醒所有
        }

    }
}
